package com.easy.util;

public class EmailCodeUtil {
    private static final ExpiryMap codeMap=new ExpiryMap(1000*60*5);

    public static String generateAndStoreCode(String email){
        String code=EmailUtil.getCode();
        codeMap.put(email, code, 1000*60*5);
        return code;
    }
    public static boolean verifyCode(String email,String code){
        String storedCode=( String) codeMap.get(email);
        return storedCode!=null && storedCode.equals(code);
    }
    public static String sendCode(String email){
        String code=generateAndStoreCode(email);
        EmailUtil.sendEmail(email, code);
        return code;
    }
}
